package com.ruoyi.iot.listener;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

import com.ruoyi.iot.domain.Command;
import com.ruoyi.iot.service.ICommandService;
import com.ruoyi.iotcommon.constant.RocketTopicConstant;
import com.ruoyi.iotcommon.domain.CommandReplyMessage;

import jakarta.annotation.Resource;

/**
 * 下发命令执行结果回复监听器
 */
@Service
@RocketMQMessageListener( topic = RocketTopicConstant.COMMAND_REPLY, consumerGroup = "iot-core-command-reply")
public class CommandReplyListener implements RocketMQListener<CommandReplyMessage>{


    @Resource
    private ICommandService commandService;
    
    @Override
    public void onMessage(CommandReplyMessage message) {
        // 更新命令记录表，更新命令执行结果，状态和描述
        Command command = new Command();
        command.setId(message.getCommandId());
        command.setCode(message.getCode());
        command.setMessage(message.getMessage());
        command.setReplyTime(message.getTime());
        commandService.updateCommand(command);
    }
    
}
